<%@page contentType="text/html" pageEncoding="utf-8"%>
<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<link href="../css/main.css" type="text/css" rel="stylesheet" />
		<link href="../css/dialog.css" rel="stylesheet" type="text/css">
		<title>企业书屋运营管理平台</title>
	</head>
	<body>
		<div class="main_frame">
			<div class="position_div">
				<img src="../images/position_icon.png" />
				<i>系统管理</i><i>&gt;&gt;</i><i>菜单管理</i>
			</div>
			<div class="right_div">
				<div class="search_div">
					<div class="label_div">
						<label class="text_label">
							菜单编号：
						</label>
						<input type="text" class="input_search" placeholder="支持模糊查询" id="menu_id" />
					</div>
					<div class="label_div">
						<label class="text_label">
							菜单名：
						</label>
						<input type="text" class="input_search" placeholder="支持模糊查询"  id="menu_name" />
					</div>
					<div class="label_div">
						<label class="text_label">
							导航显示：
						</label>
						<div class="drop_frame">
							<i class="text_i" data-status="" id="status">显示状态</i><span
								class="span_arrow"></span>
							<ul class="choose_ul">
								<li>
									<a href="javascript:void(0)" class="choose_a" data-status="0">所有</a>
								</li>
								<li>
									<a href="javascript:void(0)" class="choose_a" data-status="1">显示</a>
								</li>
								<li>
									<a href="javascript:void(0)" class="choose_a" data-status="2">不显示</a>
								</li>
							</ul>
						</div>
					</div>
					<div class="done_div">
						<button class="btn_common1 title_div2" type="button" id="submit_btn" onclick="qryMenuListByCondition()">
							<i></i>搜索
						</button>
						<button style="margin-left:10px !important" class="btn_common2 newadd" id="add_menu" type="button" onclick="addMenu()">
							<i></i>新增
						</button>
					</div>
                    <div class="cl">&nbsp;</div>
				</div>
				<table class="table_list" id="tab1">
					<tr>
						<th width="5%">
							编号
						</th>
						<th width="12%">
							菜单名称
						</th>
						<th width="12%">
							上级名称
						</th>
						<th width="24%">
							打开地址
						</th>
						<th width="7%">
							打开方式
						</th>
						<th width="7%">
							导航显示
						</th>
						<th width="18%">
							创建时间
						</th>
						<th class="last_td">
							基本操作
						</th>
					</tr>
					<tbody id="listbox1">
					</tbody>
				</table>
				
				<!-- 添加菜单信息 -->
				<div class="right_content_edit" id="addMenuBox">
					<div class="blank_div"></div>
					<label class="text_label label_width">
						上级菜单：
					</label>
					<div class="drop_frame">
						<i class="text_i" data-status="0" id="add_parentID">选择上级</i><span
							class="span_arrow"></span>
						<ul class="choose_ul" id="pmenu_choose_add">
						</ul>
					</div>
					&nbsp;&nbsp;<span style="color: red">*</span>
					<div class="blank_div"></div>
					<label class="text_label label_width">
						导航显示：
					</label>
					<div class="drop_frame">
						<i class="text_i" data-status="" id="add_showNav">显示状态</i><span
							class="span_arrow"></span>
						<ul class="choose_ul">
							<li>
								<a href="javascript:void(0)" class="choose_a" data-status="1">显示</a>
							</li>
							<li>
								<a href="javascript:void(0)" class="choose_a" data-status="2">不显示</a>
							</li>
						</ul>
					</div>
					&nbsp;&nbsp;<span style="color: red">*</span>
					<div class="blank_div"></div>
					<label class="text_label label_width">
						图标选择：
					</label>
					<div class="drop_frame">
						<i class="text_i" data-status="" id="add_headImg">选择图标</i><span
							class="span_arrow"></span>
						<ul class="choose_ul">
							<li>
								<a href="javascript:void(0)" class="choose_a" data-status="">无</a>
							</li>
							<li>
								<a href="javascript:void(0)" class="choose_a" data-status="images/menu_1">系统管理图标</a>
							</li>
							<li>
								<a href="javascript:void(0)" class="choose_a" data-status="images/menu_2">业务办理图标</a>
							</li>
						</ul>
					</div>
					<div class="blank_div"></div>
					<label class="text_label label_width">
						打开位置：
					</label>
					<div class="drop_frame">
						<i class="text_i" data-status="" id="add_showTarget">选择位置</i><span
							class="span_arrow"></span>
						<ul class="choose_ul">
							<li>
								<a href="javascript:void(0)" class="choose_a"
									data-status="mainFrame">框架内</a>
							</li>
							<li>
								<a href="javascript:void(0)" class="choose_a" data-status="_blank">新窗口</a>
							</li>
						</ul>
					</div>
					<div class="blank_div"></div>
					<label class="text_label label_width">
						菜单名称：
					</label>
					<input type="text" class="input_search width_input" id="menuname" />
					&nbsp;&nbsp;<span style="color: red">*</span>
					<div class="blank_div"></div>
					<label class="text_label label_width">
						菜单地址：
					</label>
					<input type="text" class="input_search width_input" id="menuurl" />
					&nbsp;&nbsp;<span style="color: red">*</span>
					<div class="blank_div"></div>
					<div class="bottom_donebtn width_div">
						<button class="btn_common2" id="addMenuBtn" onclick="doAddMenu()">
							提交
						</button>
						<button class="btn_common1" onclick="edit_cancel(1)">
							取消
						</button>
					</div>
				</div>
				
				<!-- 修改菜单信息 -->
				<div class="right_content_edit" id="editMenuBox">
				<input type="hidden" name="edit_id" id="edit_id" />
					<div class="blank_div"></div>
					<label class="text_label label_width">
						上级菜单：
					</label>
					<div class="drop_frame">
						<i class="text_i" data-status="0" id="edit_parentID">选择上级</i><span
							class="span_arrow"></span>
						<ul class="choose_ul" id="pmenu_choose">
						</ul>
					</div>
					&nbsp;&nbsp;<span style="color: red">*</span>
					<div class="blank_div"></div>
					<label class="text_label label_width">
						导航显示：
					</label>
					<div class="drop_frame">
						<i class="text_i" data-status="2" id="edit_showNav">显示状态</i><span
							class="span_arrow"></span>
						<ul class="choose_ul">
							<li>
								<a href="javascript:void(0)" class="choose_a" data-status="1">显示</a>
							</li>
							<li>
								<a href="javascript:void(0)" class="choose_a" data-status="2">不显示</a>
							</li>
						</ul>
					</div>
					&nbsp;&nbsp;<span style="color: red">*</span>
					<div class="blank_div"></div>
					<label class="text_label label_width">
						图标选择：
					</label>
					<div class="drop_frame">
						<i class="text_i" data-status="" id="edit_headImg">选择图标</i><span
							class="span_arrow"></span>
						<ul class="choose_ul">
							<li>
								<a href="javascript:void(0)" class="choose_a" data-status="">无</a>
							</li>
							<li>
								<a href="javascript:void(0)" class="choose_a" data-status="images/menu_1">系统管理图标</a>
							</li>
							<li>
								<a href="javascript:void(0)" class="choose_a" data-status="images/menu_2">业务办理图标</a>
							</li>
						</ul>
					</div>
					<div class="blank_div"></div>
					<label class="text_label label_width">
						打开位置：
					</label>
					<div class="drop_frame">
						<i class="text_i" data-status="" id="edit_showTarget">选择位置</i><span
							class="span_arrow"></span>
						<ul class="choose_ul">
							<li>
								<a href="javascript:void(0)" class="choose_a"
									data-status="mainFrame">框架内</a>
							</li>
							<li>
								<a href="javascript:void(0)" class="choose_a" data-status="_blank">新窗口</a>
							</li>
						</ul>
					</div>
					<div class="blank_div"></div>
					<label class="text_label label_width">
						菜单名称：
					</label>
					<input type="text" class="input_search width_input" id="edit_menuname" />
					&nbsp;&nbsp;<span style="color: red">*</span>
					<div class="blank_div"></div>
					<label class="text_label label_width">
						菜单地址：
					</label>
					<input type="text" class="input_search width_input" id="edit_menuurl" />
				    &nbsp;&nbsp;<span style="color: red">*</span>
				    <div class="blank_div"></div>
			    	<div class="bottom_donebtn width_div">
			    	<input type="hidden" id="editUid" value=""/>
			    		<button class="btn_common2" id="editMenuBtn" onclick="doEditMenu()">提交</button>
			    		<button class="btn_common1" onclick="edit_cancel(2)">取消</button>
			    	</div>
			  	</div>
				
				 <!--分页 -->
				<div class="turn_page" style="display:none">
				   <div class="main_page" id="pageCon">
					   <a href="javascript:void(0)" class="first_a" id="firstPage"></a>
					   <a href="javascript:void(0)" class="up_a" id="prev"></a>    	
					   <a href="javascript:void(0)" class="next_a" id="next"></a>
					   <a href="javascript:void(0)" class="last_a" id="lastPage"></a>
					   <input id="page_num_input" style="width:40px;" type="text" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}"/>
					   <button type="button" class="num_input" id="go_num_input">跳转</button>
					   <b class="page_text">当前<i><em id="nowpage"></em>/<em id="totalpage"></em></i>页，总数<i id="totalNum"></i>条</b>    	
				   </div>
				</div>
			</div>
		</div>
		<script type="text/javascript" src="../js/jquery-1.10.2.min.js"></script>
		<script type="text/javascript" src="../js/common.js"></script>
		<script type="text/javascript" src="../js/dialog.js"></script>
		<script type="text/javascript" src="../js/validate.js"></script>
		<script>
		var yema=1;
		var pagelen=10;
		var totalPage=0;
		function qryList(){
			qryMenuList();
		}
		$(document).ready(function() {
			qryMenuList();
		});
		//查询按钮触发事件
		function qryMenuListByCondition() {
			yema=1;
			var menu_id = $("#menu_id").val();
			if(!isEmpty(menu_id)&&!vNumber(menu_id)){
				LQWarn("菜单编号只能是数字");
				return;
			}
			qryMenuList();
		}
		//获取列表
		function qryMenuList() {
			var menu_id = $("#menu_id").val();
			var menu_name = $("#menu_name").val();
			var status=$("#status").attr("data-status");
			$.ajax({
				url: 'getMenuList.do', 
				type: 'POST',
				data:{menuID:menu_id,menuName:menu_name,navMenu:status,yema:yema,pagelen:pagelen}, 
				async: false,
				dataType: 'json', 
				timeout: 10000, 
				error: function(){LQWarn('请求失败,请稍后重试');}, 
				success: function(result){
					if(result.resultCode==1000){
						var items=result.returnObject.pageList;
						if (items.length > 0) {
							var pageMsg=result.returnObject.pageMsg;
							var rlist="";
							$.each(items,function(i){
								var item = items[i];
								//var vdate = new Date(parseInt(item.CREATETIME));
								//var date_str = vdate.getFullYear()+"年"+(vdate.getMonth()+1)+"月"+vdate.getDate()+"日  "+vdate.getHours()+"时"+vdate.getMinutes()+"分";
								var navmenu = item.NAVMENU;
								var urlTarget=item.URLTARGET;
								var parentID=item.PARENTID;
								if(navmenu==1){
									navmenu="显示";
								}else{
									navmenu="不显示";
								}
								if(urlTarget=="mainFrame"){
									urlTarget="框架内";
								}else if(urlTarget=="_blank"){
									urlTarget="新窗口";
								}else{
									urlTarget="无";
								}
								rlist+='<tr><td>'+item.ID+'</td><td>'+item.MENUNAME+'</td><td>'+item.PARENTNAME+'</td><td>'+item.MENUURL+'</td><td>'+urlTarget+'</td><td>'+navmenu+'</td><td>'+format(item.CREATETIME)+'</td><td class="last_td"><input type="hidden" value='+item.HEADIMG+' name="headImg"/><input type="hidden" value='+parentID+' name="parentID"/><p class="mod" onclick="editMenu(this)">修改</p><p class="del" onclick="delMenu('+item.ID+')">删除</p></td></tr>';
								/* rlist+='<tr><td>'+item.ID+'</td><td>'+item.MENUNAME+'</td><td>'+item.PARENTNAME+'</td><td>'+item.MENUURL+'</td><td>'+urlTarget+'</td><td>'+navmenu+'</td><td>'+format(item.CREATETIME)+'</td><td class="last_td"><input type="hidden" value='+item.HEADIMG+' name="headImg"/><input type="hidden" value='+parentID+' name="parentID"/><button class="edit_btn btn_motify" title="修改" onclick="editMenu(this)">修改</button><button class="edit_btn btn_delete" title="删除" onclick="delMenu('+item.ID+')">删除</button></td></tr>'; */
							});
							$("#listbox1").html(rlist);
							totalPage=result.returnObject.totalPage;
							$("#nowpage").html(result.returnObject.curPage);
							$("#totalpage").html(totalPage);
							$("#totalNum").html(result.returnObject.totalNum);
							$(".turn_page").show();
						}else{
							$("#listbox1").html("");
							$(".turn_page").hide();
						}
					}
					else if(result.resultCode==1004){
						LQWarn(result.returnObject);
						window.top.location.href ="../login.jsp";
					}else{
						LQWarn(result.returnObject);
					}
				}
			});
		}
	
		//显示添加页面-隐藏主页面
		function addMenu(){
		$("#menuname").val("");
		$("#menuurl").val("");
		$("#add_parentID").attr("data-status","");
		$("#add_parentID").html("选择上级");
		$("#add_showNav").attr("data-status","");
		$("#add_showNav").html("显示状态");
		$("#add_showTarget").attr("data-status","");
		$("#add_showTarget").html("打开位置");
		$("#add_headImg").attr("data-status","");
		$("#add_headImg").html("选择图标");
			$(".search_div,.table_list").hide();
			$(".turn_page").hide();
			$("#addMenuBox").show();
			getLeftMenu(1);
		}
		
		//删除菜单
		function delMenu(menu_id){
			LQConfirm("您确定要删除该菜单吗？",function(){
				$.ajax({
					url: 'delMenu.do', 
					type: 'POST',
					data:{menuID:menu_id}, 
					async: false,
					dataType: 'json', 
					timeout: 10000, 
					error: function(){LQWarn('请求失败,请稍后重试');}, 
					success: function(result){
						if(result.resultCode==1000){
							LQMsg("删除成功");
							qryMenuList();
						}
						else if(result.resultCode==1004){
							LQWarn(result.returnObject);
							window.top.location.href ="../login.jsp";
						}else{
							LQWarn(result.returnObject);
						}
					}
				});	
			});
		}
		//显示修改页面-隐藏主页面
		function editMenu(ob){
			//判断权限后打开修改页面
			$.ajax({
				url: 'editMenu.do', 
				type: 'POST',
				async: false,
				dataType: 'json', 
				timeout: 10000, 
				error: function(){LQWarn('请求失败,请稍后重试');}, 
				success: function(result){
					if(result.resultCode==1000){
						getLeftMenu(2);
						var _this=$(ob),
						tr=_this.parents("tr");
						$("#edit_menuurl").val(tr.find('td').eq(3).text());
						$("#edit_menuname").val(tr.find('td').eq(1).text());
						if(tr.find('td').eq(4).text()=="无"){
							$("#edit_showTarget").attr("data-status","");
						}else if(tr.find('td').eq(4).text()=="新窗口"){
							$("#edit_showTarget").attr("data-status","_blank");
						}else if(tr.find('td').eq(4).text()=="框架内"){
							$("#edit_showTarget").attr("data-status","mainFrame");
						}
						$("#edit_showTarget").html(tr.find('td').eq(4).text());
						$("#edit_showNav").attr("data-status",tr.find('td').eq(5).text()=="显示"?"1":"2");
						$("#edit_showNav").html(tr.find('td').eq(5).text());
						if(tr.find("input[name=headImg]").val()=="images/menu_1"){
							$("#edit_headImg").html("系统管理图标");
						}else if(tr.find("input[name=headImg]").val()=="images/menu_2"){
							$("#edit_headImg").html("业务办理图标");
						}
						$("#edit_headImg").attr("data-status",tr.find("input[name=headImg]").val());
						$("#edit_parentID").attr("data-status",tr.find("input[name=parentID]").val());
						$("#edit_parentID").html(tr.find('td').eq(2).text());
						$("#edit_id").val(tr.find('td').eq(0).text());
						$(".table_list,.search_div,.turn_page").hide();
						$("#editMenuBox").show();
					}
					else if(result.resultCode==1004){
						LQWarn(result.returnObject);
						window.top.location.href ="../login.jsp";
					}else{
						LQWarn(result.returnObject);
					}
				}
			});	
		}
		//修改页面--获取左侧菜单
		function getLeftMenu(type) {
			$.ajax({
				url: '../getLeftMenu.do', 
				type: 'POST',
				async: false,
				dataType: 'json', 
				timeout: 10000, 
				error: function(){LQWarn('请求失败,请稍后重试');}, 
				success: function(result){
					if(result.resultCode==1000){
						var items=result.returnObject;
						if (items.length > 0) {
							var fnav='<li><a href="javascript:void(0)" class="choose_a" data-status="0">根菜单</a></li>';
							$.each(items,function(i){
								var item = items[i];
								fnav+='<li><a href="javascript:void(0)" class="choose_a" data-status="'+item.ID+'">'+item.MENUNAME+'</a></li>';
								var childList=item.childList;
								$.each(childList,function(k){
									fnav+='<li><a href="javascript:void(0)" class="choose_a" data-status="'+childList[k].ID+'">'+childList[k].MENUNAME+'</a></li>';
								});
							});
							if(type==2){
								$("#pmenu_choose").html(fnav);
							}else if(type==1){
								$("#pmenu_choose_add").html(fnav);
							}
						}
					}else if(result.resultCode==1004){
						LQWarn(result.returnObject);
						top.location.href ="../login.jsp";
					}else{
						LQWarn(result.returnObject);
					}
				}
				}); 
		}
		//修改页面取消按钮事件
		function edit_cancel(etype){
			$(".search_div,.table_list").show();
			$(".turn_page").show();
			if(etype==1){
				$("#addMenuBox").hide();
			}else if(etype==2){
				$("#editMenuBox").hide();
			}
		}
		//添加菜单
		function doAddMenu(){
			var menuname = $.trim($("#menuname").val());
			var menuurl = $.trim($("#menuurl").val());
			var parentid=$("#add_parentID").attr("data-status");
			var navmenu=$("#add_showNav").attr("data-status");
			var urltarget=$("#add_showTarget").attr("data-status");
			var headImg=$("#add_headImg").attr("data-status");
			if(parentid==""){
				LQWarn("请选择上级菜单");
				return;
			}
			if(navmenu==""){
				LQWarn("请选择导航显示");
				return;
			}
			if(menuname==""){
			    $("#menuname").focus();
				LQWarn("请输入菜单名称");
				return;
			}
			if(menuurl==""){
			    $("#menuurl").focus();
				LQWarn("请输入菜单地址");
				return;
			}
			$.ajax({
				url: 'doAddMenu.do', 
				type: 'POST',
				async: false,
				data:{menuName:menuname,menuUrl:menuurl,parentID:parentid,navMenu:navmenu,urlTarget:urltarget,headImg:headImg}, 
				dataType: 'json', 
				timeout: 10000, 
				error: function(){LQWarn('请求失败,请稍后重试');}, 
				success: function(result){
					if(result.resultCode==1000){
						LQMsg("添加成功");
						edit_cancel(1);
						qryMenuList();
					}else if(result.resultCode==1004){
						LQWarn(result.returnObject);
						top.location.href ="../login.jsp";
					}else{
						LQWarn(result.returnObject);
					}
				}
			}); 
		}
		//编辑提交按钮
		function doEditMenu(){
			var menuID=$("#edit_id").val();
			var menuname = $.trim($("#edit_menuname").val());
			var menuurl = $.trim($("#edit_menuurl").val());
			var parentid=$("#edit_parentID").attr("data-status");
			var navmenu=$("#edit_showNav").attr("data-status");
			var urltarget=$("#edit_showTarget").attr("data-status");
			var headImg=$("#edit_headImg").attr("data-status");
			if(parentid==""){
				LQWarn("请选择上级菜单");
				return;
			}
			if(navmenu==""){
				LQWarn("请选择导航显示");
				return;
			}
			if(menuname==""){
			    $("#edit_menuname").focus();
				LQWarn("请输入菜单名称");
				return;
			}
			if(menuurl==""){
			    $("#edit_menuurl").focus();
				LQWarn("请输入菜单地址");
				return;
			}
			$.ajax({
				url: 'doEditMenu.do', 
				type: 'POST',
				data:{menuID:menuID,menuName:menuname,menuUrl:menuurl,parentID:parentid,navMenu:navmenu,urlTarget:urltarget,headImg:headImg},
				async: false,
				dataType: 'json', 
				timeout: 10000, 
				error: function(){LQWarn('请求失败,请稍后重试');}, 
				success: function(result){
					if(result.resultCode==1000){
						LQMsg("修改成功");
						edit_cancel(2);
						qryMenuList();
					}
					else if(result.resultCode==1004){
						LQWarn(result.returnObject);
						window.top.location.href ="../login.jsp";
					}else{
						LQWarn(result.returnObject);
					}
				}
			});	
		}
		</script>
	</body>
</html>
